/**
 * 
 */
package com.dianwoba.core.jackson;

import java.math.BigDecimal;
import java.math.RoundingMode;

import com.fasterxml.jackson.databind.JavaType;
import com.fasterxml.jackson.databind.type.SimpleType;
import com.fasterxml.jackson.databind.type.TypeFactory;
import com.fasterxml.jackson.databind.util.Converter;

/**
 * @author Zhu
 * @date 2015-12-10 下午8:53:31
 * @description
 */
public class KilometerConverter implements Converter<Integer, String> {

	private BigDecimal multiple = new BigDecimal(1000);

	/*
	 * (non-Javadoc)
	 * 
	 * @see
	 * com.fasterxml.jackson.databind.util.Converter#convert(java.lang.Object)
	 */
	@Override
	public String convert(Integer value) {
		return new BigDecimal(value).divide(multiple, 1, RoundingMode.UP)
				+ "千米";
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see
	 * com.fasterxml.jackson.databind.util.Converter#getInputType(com.fasterxml
	 * .jackson.databind.type.TypeFactory)
	 */
	@Override
	public JavaType getInputType(TypeFactory typeFactory) {
		return SimpleType.construct(Integer.class);
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see
	 * com.fasterxml.jackson.databind.util.Converter#getOutputType(com.fasterxml
	 * .jackson.databind.type.TypeFactory)
	 */
	@Override
	public JavaType getOutputType(TypeFactory typeFactory) {
		return SimpleType.construct(String.class);
	}

}
